<? echo $this->render("header.phtml"); ?>
<label class="title">Category management</label>&nbsp;|&nbsp;
<label for="section">Select a section:</label>
<select id="section" name="section" onchange="javascript:eway.redirect('<?= $this->baseUrl ?>/<?= $this->contextPath ?>/index/section/' + this.value);">
	<? foreach ($this->sections as $section): ?>
		<option value="<?= $section->sec_id ?>" <?= (($this->currentSection == $section->sec_id) ? "selected" : "") ?>><?= $section->sec_name ?></option>
	<? endforeach; ?>
</select>

<div class="horiz_sep">&nbsp;</div>
<a href="<?= $this->baseUrl ?>/<?= $this->contextPath ?>/add">Add a new category</a><br/><br/>
<table cellpadding="8" cellspacing="0" width="100%" border="0" style="border: 1px solid #81d2f6; border-bottom: 0px">
	<tr style="background-color: #81d2f6;">
		<td width="1%">#</td>
		<td width="20%">Category name</td>
		<td width="49%">Description</td>
		<td width="10%">Position</td>
		<td width="20%">Operations</td>
	</tr>
	<? if ($this -> categories): ?>
	<? $index = 1; foreach ($this -> categories as $category): ?>
		<tr>
			<td style="border-bottom: 1px solid #81d2f6;"><? echo $index ++; ?></td>
			<td align="left" style="border-bottom: 1px solid #81d2f6;"><? echo $category -> cat_name; ?></td>
			<td align="left" style="border-bottom: 1px solid #81d2f6;"><? echo $category -> cat_description; ?></td>
			<td align="left" style="border-bottom: 1px solid #81d2f6;">
				<select id="position" name="position" onchange="javascript:eway.redirect('<?= $this->baseUrl ?>/<?= $this->contextPath ?>/position/id/<?= $category->cat_id ?>/val/' + this.value);">
				<? for ($i = 0; $i < $this->count; $i ++): ?>
					<option value="<?= ($i + 1) ?>" <?= (($category -> cat_position) == ($i + 1)) ? "selected" : "" ?>><?= ($i + 1) ?></option>
				<? endfor; ?>
				</select>
			</td>
			<td align="left" style="border-bottom: 1px solid #81d2f6;">
				<a	href="<? echo $this -> baseUrl ?>/<?= $this->contextPath ?>/edit/id/<? echo $category -> cat_id ?>">Edit</a>
				&nbsp;&nbsp;
				<a	href="javascript:eway.confirm('<? echo $this -> baseUrl ?>/<?= $this->contextPath ?>/delete/id/<? echo $category -> cat_id ?>', 'Are you sure you want to delete this category?');">Delete</a>
			</td>
		</tr>
	<? endforeach; ?>
	<? endif; ?>
</table>
<? if (((int)$this -> pages) > 1): ?>
	<table cellpadding="8" cellspacing="0" width="100%" border="0">	
		<tr>
			<td colspan="6" align="center">
				Page:
				<? for ($i = 0; $i < $this -> pages; $i ++): ?>
					<a href="<? echo $this -> baseUrl; ?>/<?= $this->contextPath ?>/index/page/<? echo ($i + 1); ?>"><? echo $i + 1; ?></a>
					&nbsp;&nbsp;
				<? endfor; ?>
			</td>
		</tr>
	</table>
<? endif; ?>
<? echo $this->render("footer.phtml"); ?>